function getStyleXml() {
    $.ajax({
        type: "GET",
        url: "/static/xml/style.xml",
        dataType: "xml",
        success: update_styleXml
    });
};

var styleXml = null;
function update_styleXml(xml){
	styleXml = xml;
	$(xml).find("style").each(function(){
		$(document.createElement("option")).attr("value", $(this).attr("id")).text($(this).attr("name"))
			.appendTo("select#css-template");
	});
}

function xmlParser(xml) {

    $('#load').fadeOut();

    $(xml).find("Book").each(function () {

        $(".main").append('<div class="book"><div class="title">' + $(this).find("Title").text() + '</div><div class="description">' + $(this).find("Description").text() + '</div><div class="date">Published ' + $(this).find("Date").text() + '</div></div>');
        $(".book").fadeIn(1000);

    });

}

function addCssTemplate(table, styleId){
	if (!styleXml) return;
	
	$(styleXml).find("style#" + styleId).children("css").each(function(){
		var tr = $("table tr#css_key_value").clone(true,true).appendTo(table).attr("id", "").show();
		
		var property = $(this).attr("property");
		var value = $(this).attr("value");
		
		tr.find("td:first").text(property);
		tr.find("td:eq(1)").text(value);
		
		var elementId = $(table).attr("elementId");
		basic_set_prop(elementId, property, value);	//basic_htmle.js
	});
	
	return table;
}